<?php


class evl{
	
	var $items;
	var $oneA;
	var $moreA;
	var $zeroA;	
	
	function __construct($file,$pre=""){
		
		$this->pre = $pre;
		
		$this->items = array();
		$this->oneA = array();
		$this->moreA = array();
		$this->zeroA = array();
		
		$arr = array();
		if(!($handle = fopen($file,"r"))) die("Konnte Datei nicht öffnen!\n");
		while(!feof($handle)) {
			$line = trim(fgets($handle));
			if(preg_match('/^!/',$line)) continue; //Kommentarzeile
			if(preg_match('/^\?{3}/',$line)) continue;//keine Analyse
			if(preg_match('/^(\s+)?$/',$line)){ // leere Zeile->schließt Item
				if(!empty($arr))
					$this->items[] = $arr;			
				$arr = array();
				continue;
			}
			$arr[] = $line;
		}
		if(!empty($arr))
			$this->items[] = $arr;
	}
	
	function summary(){
		
		$this->counting();
		 
		// Logdateien
		foreach(array("noAnalyse"=>"zeroA","oneAnalyse"=>"oneA","moreAnalyses"=>"moreA") as $file=>$var){
			$handle = fopen("logs/".$file."/log.".$this->pre.".".$file.".txt","w");
			foreach($this->{$var} as $item)
				fwrite($handle,implode("\n",$item)."\n");
			fclose($handle);
		}
		
		echo "Eine Analyse: ".count($this->oneA)."\n";
		echo "Mehrere Analysen: ".count($this->moreA)."\n";
		echo "Keine Analyse: ".count($this->zeroA)."\n";				
	}
	
	function counting(){
		foreach($this->items as $item){
			$c = count($item);
			if($c==1){
				$this->zeroA[] = $item;				
			} elseif($c==2){
				$this->oneA[] = $item;
			} elseif($c>2){
				$this->moreA[] = $item;
			}
		}
	}
	
}
echo "== NoLex ==\n";
echo "Wiki\n";
$test = new evl("out/out.wiki.nolex.txt","wiki.nolex");
$test->summary();
echo "NZZ\n";
$test = new evl("out/out.nzz.nolex.txt","nzz.nolex");
$test->summary();
echo "IMSLex\n";
$test = new evl("out/out.imslex.nolex.txt","imslex.nolex");
$test->summary();
echo "== Lex ==\n";
echo "Wiki\n";
$test = new evl("out/out.wiki.lex.txt","wiki.lex");
$test->summary();
echo "NZZ\n";
$test = new evl("out/out.nzz.lex.txt","nzz.lex");
$test->summary();
echo "IMSLex\n";
$test = new evl("out/out.imslex.lex.txt","imslex.lex");
$test->summary();


?>